package com.fgr.controller;

import com.fgr.beans.Admin;
import com.fgr.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ResponseBody;


import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
public class AdminController {
    @Autowired
    AdminService adminService;

    @ResponseBody
    @PostMapping("loginAdmin")
    public String loginAdmin(Admin admin, HttpSession httpSession){
        String s = adminService.AdminLogin(admin,httpSession);
        return s;
    }

    @GetMapping("selectAllAdmin")
    public String selectAllAdmin(Model model){
        List<Admin> admins = adminService.allAdmin();
        model.addAttribute("admins",admins);
        return "background/admin";
    }

    @GetMapping("findAdminById")
    public String findAdminById(Integer glId,Model model){
        Admin admin = adminService.findAdminById(glId);
        model.addAttribute("admin",admin);
        return "background/modifyadmin";
    }

    @ResponseBody
    @PostMapping("UpdateAdmin")
    public String UpdateAdmin(Admin admin){
        String s = adminService.UpdateAdmin(admin);
        return s;
    }

    @ResponseBody
    @PostMapping("DeleteAdmin")
    public String DeleteAdmin(Integer glId){
        String s = adminService.DeleteAdmin(glId);
        return s;
    }

    @ResponseBody
    @PostMapping("addAdmin")
    public String addAdmin(Admin admin){
        String s = adminService.AddAdmin(admin);
        return s;
    }


}
